﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DalatCooking.Core;
using System.Web.Security;
public partial class Role_Login : System.Web.UI.Page
{
    private void Page_Load(object sender, System.EventArgs e)
    {

    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.Ok.Click += new System.EventHandler(this.Ok_Click);
        this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void Ok_Click(object sender, System.EventArgs e)
    {
        CustomPrincipal newUser = CustomPrincipal.ValidateLogin(Email.Text, Password.Text);

        if (newUser == null)
        {
            ErrorMessage.Text = "Login failed for " + Email.Text;
            ErrorMessage.Visible = true;
        }
        else
        {
            Context.User = newUser;
            FormsAuthentication.SetAuthCookie(Email.Text, true);
            Response.Redirect("Default.aspx");
        }
    }
}